﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 作业
{
    public partial class Calculator : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnSub_Click(object sender, EventArgs e)
        {
            string sign = DrDoSign.SelectedValue;
            double num1 = 0;
            double num2 = 0;
            try
            {
                num1 = double.Parse(TxtNum1.Text);
                num2 = double.Parse(TxtNum2.Text);
            }
            catch (FormatException)
            {
                Response.Write("<script>alert('请补全数字');</script>");
                return;
            }
            switch (sign)
            {
                case "+":
                    LabResult.Text = String.Format("{0} + {1} = {2}", num1, num2, num1 + num2);
                    break;
                case "-":
                    LabResult.Text = String.Format("{0} - {1} = {2}", num1, num2, num1 - num2);
                    break;
                case "*":
                    LabResult.Text = String.Format("{0} * {1} = {2}", num1, num2, num1 * num2);
                    break;
                case "/":
                    if (num2 == 0)
                    {
                        Response.Write("<script>alert('被除数不能为0，请重新输入！');</script>");
                        break;
                    }
                    LabResult.Text = String.Format("{0} / {1} = {2}", num1, num2, num1 / num2);
                    break;
            }
        }
    }
}